package cz.myslivec.knihovna.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

import cz.myslivec.knihovna.entity.Author;

@Name("authorDaoImpl")
@AutoCreate
public class AuthorDaoImpl implements AuthorDao {

	@In
	private EntityManager entityManager;
	
	public void create(Author author) {
		entityManager.persist(author);
	}

	public void delete(Author author) {
		entityManager.remove(author);
	}
	
	public void update(Author author) {
		entityManager.merge(author);
	}

	public Author getAuthor(long id) {
		// TODO Auto-generated method stub
		return null;
	}

	public Author findByName(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<Author> list() {
		Query query = entityManager.createQuery("from Author");
		return (List<Author>)query.getResultList();
	}

}
